package 校招笔试.美团笔试.美23812;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/8/15 16:15
 */
public class Test {


    public static void main(String[] args) {
        new Test().solve();
    }
    int n;
    int[] v;
    List<List<Integer>> graph = new ArrayList<>();
    void solve() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        v = new int[n+1];
        for (int i = 1; i <= n; i++) {
            v[i] = sc.nextInt();
        }
        for (int i = 0; i <= n; i++) graph.add(new LinkedList<>());

        int res = 0;
        for (int i = 0 ; i < n  - 1; i ++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        dp = new int[n+1][2];
        dfs(1,-1);
        System.out.println(Math.max(dp[1][0], dp[1][1]));
    }

    int[][] dp; //node 0不染色 1染色

    void dfs(int node, int pre) {
        for (int next : graph.get(node)) {
            if (next != pre) {
                dfs(next,node);
            }
        }

        if (graph.get(node).size() == 0 && graph.get(node).get(0) == pre) {
            dp[node][1] = 1;
        }

        //不染色
        int tmp = 0;
        for (int next : graph.get(node)) {
            if (next != pre) {
                dp[node][0] += Math.max(dp[next][0], dp[next][1]) ;
                tmp += dp[next][0];
            }
        }

        for (int next : graph.get(node)) {
            if (next != pre) {
                if (isAns(v[next], v[node])) dp[node][1] = Math.max(dp[node][0] - Math.max(dp[next][0], dp[next][1])+2+dp[next][0], dp[node][1]);
            }
        }
    }

    boolean isAns(int a, int b) {
        if (a < 0 || b < 0) return false;
        long c = a*b;
        int sq = (int) Math.sqrt(c);
        return sq*sq == c;
    }
}
